package org.ct.dataobjects;

import java.util.Comparator;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;

@Entity
@NamedQuery(name = "sortById", query = "from Student order by id")
public class Student extends DataObject {

	@Id
	private Integer id;
	private String firstName;
	private String surname;

	public Student() {
	}

	public Student(Integer id, String firstName, String surname) {
		this();
		this.id = id;
		this.firstName = firstName;
		this.surname = surname;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public static StudentIdComparator getIdComparator() {
		return new StudentIdComparator();
	}

}

class StudentIdComparator implements Comparator<Student> {
	@Override
	public int compare(Student s1, Student s2) {
		if (s1 == null) return 1;
		if (s2 == null) return -1;
		return s1.getId().compareTo(s2.getId());
	}
}